﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LevelEditor.App;

namespace LevelEditor
{
    public partial class FiletypeSelector : Form
    {
        private string fileType;
        public string FileType
        {
            get { return fileType; }
        }

        DialogResult result;
        private bool wantToClose;


        public FiletypeSelector()
        {
            InitializeComponent();

            this.result = System.Windows.Forms.DialogResult.Cancel;
            this.wantToClose = false;

            this.FormClosing += FiletypeSelector_FormClosing;
        }

        void FiletypeSelector_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing && !wantToClose)
            {
                result = System.Windows.Forms.DialogResult.Cancel;
            }
        }

        private void typeSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.fileType = this.typeSelector.Items[this.typeSelector.SelectedIndex].ToString().Replace(" ","");
            this.wantToClose = true;
        }

        public new DialogResult ShowDialog()
        {
            base.ShowDialog();

            return result;
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.fileType))
            {
                ErrorController.ShowOkError(ErrorController.LevelEditorError.APP_NO_FILE_TYPE_SELECTED);
                return;
            }
            this.wantToClose = true;
            this.result = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
